<?php
namespace app\admin\model;

use app\model\Base;

class Goods extends Base
{
    public function getCoverFormatAttr($value, $data)
    {
        return get_oss_url($data['cover']);
    }

    public function getImagesFormatAttr($value, $data)
    {
        $arr = [];
        if(!is_null($data['images'])){
            if($data['images'] != 'null'){
                $images = json_decode($data['images'], true);
                foreach ($images as $image){
                    $arr[] = get_oss_url($image);
                }
            }
        }
        return $arr;
    }

    public function getContentFormatAttr($value, $data)
    {
//        return 111;
        $arr = [];
        if(!is_null($data['content'])){
            if($data['content'] != 'null'){
                $images = json_decode($data['content'], true);
//                $images = explode(',', $data['content']);
                foreach ($images as $image){
                    $arr[] = get_oss_url($image);
                }
            }
        }
        return $arr;
    }

    public function getImagesParseAttr($value, $data)
    {
        $arr = [];
        if(!is_null($data['images'])){
            if($data['images'] != 'null'){
                $images = json_decode($data['images'], true);
//                $images = explode(',', $data['content']);
                foreach ($images as $image){
                    $arr[] = $image;
                }
            }
        }
        return $arr;
    }

    public function getContentParseAttr($value, $data)
    {
//        $str = '[]';
//        if(!is_null($data['content'])){
//            if($data['content'] != 'null'){
//                $images = explode(',', $data['content']);
//                $str = json_encode($images);
//            }
//        }
//        return $str;
        $arr = [];
        if(!is_null($data['content'])){
            if($data['content'] != 'null'){
                $images = json_decode($data['content'], true);
//                $images = explode(',', $data['content']);
                foreach ($images as $image){
                    $arr[] = $image;
                }
            }
        }
        return $arr;
    }

    public function getMarketAmountFormatAttr($value, $data)
    {
        return bcdiv_amount($data['market_amount']);
    }

    public function getSaleAmountFormatAttr($value, $data)
    {
        return bcdiv_amount($data['sale_amount']);
    }

    public function getSaleAmount1FormatAttr($value, $data)
    {
        return bcdiv_amount($data['sale_amount1']);
    }

    public function getSaleAmount2FormatAttr($value, $data)
    {
        return bcdiv_amount($data['sale_amount2']);
    }

    public function getSaleAmount3FormatAttr($value, $data)
    {
        return bcdiv_amount($data['sale_amount3']);
    }

    public function getSaleAmount4FormatAttr($value, $data)
    {
        return bcdiv_amount($data['sale_amount4']);
    }

    public function getSaleAmount5FormatAttr($value, $data)
    {
        return bcdiv_amount($data['sale_amount5']);
    }
}